home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / roundoff.c < prev    next >
C/C++ Source or Header  |  1993-06-20  |  3KB  |  120 lines

  1.  
  2.        /***********************************************
  3.        *
  4.        *       file d:\cips\roundoff.c
  5.        *
  6.        *       Functions: This file contains
  7.        *          main
  8.        *
  9.        *       Purpose:
  10.        *          This program takes an image file and
  11.        *          rounds if off by writing it to an new
  12.        *          file that has an even multiple of
  13.        *          rows and cols.
  14.        *
  15.        *       External Calls:
  16.        *          tiff.c - read_tiff_header
  17.        *          rtiff.c - read_tiff_image
  18.        *          gin.c - get_image_name
  19.        *          gpcips - get_parameters
  20.        *          numcvrt.c - get_integer
  21.        *          wtiff.c - create_allocate_tiff_file
  22.        *                    write_array_into_tiff_image
  23.        *
  24.        *       Modifications:
  25.        *          31 March 1991 - created
  26.        *          8  May 1993 - Made this program
  27.        *                        command line driven.
  28.        *
  29.        ***********************************************/
  30.  
  31. #include "cips.h"
  32.  
  33.  
  34.  
  35. short the_image[ROWS][COLS];
  36. short out_image[ROWS][COLS];
  37.  
  38. main(argc, argv)
  39.    int argc;
  40.    char *argv[];
  41. {
  42.    char     caption[80], name[80], name2[80], rep[80];
  43.    int      count, i, ie, il, j, le, length, ll,
  44.             new_ie, new_il, vertical, width;
  45.    struct   tiff_header_struct image_header;
  46.  
  47.  
  48.  
  49.    my_clear_text_screen();
  50.  
  51.    if(argc < 5   ||
  52.      (argc > 5  &&  argc < 7)){
  53.       printf("\nusage: roundoff in-image out-image"
  54.           " length width [il ie]"
  55.           "\n"
  56.           "\n       length and width to be multiplied"
  57.           " by ROWS and COLS"
  58.           "\n"
  59.           "\n       If you do not specify il ie"
  60.           " they will be set to 1 1."
  61.           "\n       ll le will always be"
  62.           " il+ROWS and ie+COLS"
  63.           "\n");
  64.       exit(0);
  65.    }
  66.  
  67.    new_ie = 1;
  68.    new_il = 1;
  69.  
  70.    strcpy(name,  argv[1]);
  71.    strcpy(name2, argv[2]);
  72.    length = atoi(argv[3]);
  73.    width  = atoi(argv[4]);
  74.  
  75.    if(argc > 5){
  76.       il = atoi(argv[5]);
  77.       ie = atoi(argv[6]);
  78.       ll = il + ROWS;
  79.       le = ie + COLS;
  80.    }
  81.    else{
  82.       il     = 1;
  83.       ie     = 1;
  84.       ll     = ROWS;
  85.       le     = COLS;
  86.    }
  87.  
  88.  
  89.    printf("\nCreating the output image file %s", 
  90.           name2);
  91.    read_tiff_header(name, &image_header);
  92.    image_header.image_length = length*ROWS;
  93.    image_header.image_width  = width*COLS;
  94.    if(image_header.bits_per_pixel == 4)
  95.       image_header.bits_per_pixel = 8;
  96.    create_allocate_tiff_file(name2, &image_header,
  97.                              out_image);
  98.  
  99.    count = 1;
  100.  
  101.    for(i=0; i<length; i++){
  102.       for(j=0; j<width; j++){
  103.          printf("\nRunning %d of %d", 
  104.                 count, length*width);
  105.          count++;
  106.          read_tiff_image(name, the_image,
  107.                          il + i*ROWS,
  108.                          ie + j*COLS,
  109.                          il + i*ROWS + ROWS,
  110.                          ie + j*COLS + COLS);
  111.          write_array_into_tiff_image(name2, the_image,
  112.                          new_il + i*ROWS,
  113.                          new_ie + j*COLS,
  114.                          new_il + i*ROWS + ROWS,
  115.                          new_ie + j*COLS + COLS);
  116.       }
  117.    }
  118.  
  119. }  /* ends main */
  120.